using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using Entites;

namespace DAL
{
  public  class TinhTrangThanhToanDAL
    {
      
            private SqlConnection cn = null;
        public TinhTrangThanhToanDAL()
        {
            cn = new SqlConnection(ConfigurationManager.ConnectionStrings["strConnection"].ConnectionString);
            cn.Open();
        }
       public void Insert (TinhTrangThanhToan tttt )
        {
            SqlCommand cm = new SqlCommand("TinhTrangThanhToan_insert", cn);
            cm.CommandType = CommandType.StoredProcedure;
           
           cm.Parameters.AddWithValue("@TenTTTT",tttt.tentttt);
            cm.ExecuteNonQuery();
        }
        public void Update(TinhTrangThanhToan tttt)
        {
            SqlCommand cm = new SqlCommand("TinhTrangThanhToan_update", cn);
            cm.CommandType = CommandType.StoredProcedure;
            cm.Parameters.AddWithValue("@MaTTTT", tttt.matttt);
            cm.Parameters.AddWithValue("@TenTTTT",tttt.tentttt);
           
          cm.ExecuteNonQuery();
        }
        public void Delete(int iD)
        {
            SqlCommand cm = new SqlCommand("TinhTrangThanhToan_delete", cn);
            cm.CommandType = CommandType.StoredProcedure;
            cm.Parameters.AddWithValue("@MaTTTT", iD);
            cm.ExecuteNonQuery();
        }

        public tbTinhTrangThanhToanCollection Get(string where, int pageIndex, int pageSize,
            string orderBy, string orderDirection, out int totalRecords)
        {
            SqlCommand cm = new SqlCommand("TinhTrangThanhToan_get", cn);
            cm.CommandType = CommandType.StoredProcedure;
            cm.Parameters.AddWithValue("@Where", where);
            cm.Parameters.AddWithValue("@PageIndex", pageIndex);
            cm.Parameters.AddWithValue("@PageSize", pageSize);
            cm.Parameters.AddWithValue("@OrderBy", orderBy);
            cm.Parameters.AddWithValue("@OrderDirection", orderDirection);
            cm.Parameters.Add(new SqlParameter("@TotalRecords", DbType.Int32)).Direction = ParameterDirection.Output;

            SqlDataReader dr = cm.ExecuteReader();
            tbTinhTrangThanhToanCollection ttttCollection = new tbTinhTrangThanhToanCollection();

            while (dr.Read())
            {
                TinhTrangThanhToan tinhtrangthanhtoan = new TinhTrangThanhToan();
                tinhtrangthanhtoan.matttt = int.Parse(dr.GetValue(0).ToString());
                tinhtrangthanhtoan.tentttt = dr.GetValue(1).ToString();

            
                ttttCollection.Add(tinhtrangthanhtoan);
             }
            dr.Close();
            totalRecords = int.Parse(cm.Parameters["@TotalRecords"].Value.ToString());
            return ttttCollection;
        }
    }
    }

